package com.my_musc_service.controller;

import com.my_musc_service.common.R;
import com.my_musc_service.entity.*;
import com.my_musc_service.service.SharedCommentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (SharedComment)表控制层
 *
 * @author A.Dun
 * @since 2021-08-17 14:13:47
 */
@RestController
@RequestMapping("sharedComment")
public class SharedCommentController extends BaseController{
    /**
     * 服务对象
     */
    @Resource
    private SharedCommentService sharedCommentService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public SharedComment selectOne(Integer id) {
        return this.sharedCommentService.queryById(id);
    }

    /**
     * 获取分享评论【树状结构】
     * @param sharedCommentData
     * @return
     */
    @GetMapping("getComment")
    public R getCommentVOBySharedCommentData(SharedCommentData sharedCommentData) {
        List<SharedCommentVO> childCommentList = sharedCommentService.getSharedCommentVOByCommentData(sharedCommentData);
        return R.ok().data("childCommentList", childCommentList);
    }


    /**
     * 获取热评
     *
     */
    @GetMapping("getHotComments")
    public R getHotCommentsBySharedCommentData(SharedCommentData sharedCommentData) {
        List<SharedCommentVO> hotCommentList = sharedCommentService.getHotCommentsBySharedCommentData(sharedCommentData);
        return R.ok().data("childCommentList", hotCommentList);
    }


    /**
     * 添加分享评论
     * @param sharedComment
     * @return
     */
    @PostMapping("add")
    public R addSharedComment(@RequestBody SharedComment sharedComment){
        Boolean flag = sharedCommentService.insert(sharedComment);
        return isOk(flag);
    }

    @PutMapping("addClickCount")
    public R addClickCount(@RequestBody SharedComment sharedComment){
        Boolean flag=sharedCommentService.addClickCount(sharedComment);
        return isOk(flag);
    }
    @PutMapping("delClickCount")
    public R delClickCount(@RequestBody SharedComment sharedComment){
        Boolean flag=sharedCommentService.delClickCount(sharedComment);
        return isOk(flag);
    }

}
